using DG.Tweening;
using DG.Tweening.Core;
using UnityEngine;

namespace WorkFlow.TweenGo
{
    [RequireComponent(typeof(SpriteRenderer))]
    public class SpriteRendererAlphaTween : TweenGoBase<Transform,float>
    {
        SpriteRenderer _spriteRenderer;
        protected override Tweener CreateTween(DOGetter<float> startValueGetter, DOSetter<float> setter, float endValue, float duration)
        {
            return DOTween.To(startValueGetter, setter, endValue, duration);
        }

        protected override void SetValue(float value)
        {
            if (_spriteRenderer == null)
            {
                _spriteRenderer = GetComponent<SpriteRenderer>();
            }
            Color color = _spriteRenderer.color;
            color.a = value;
            _spriteRenderer.color = color;
        }
    }
}
